/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import POJO.Khuvuc;
import UTIL.HibernateUtil;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 *
 * @author nhlvu07db373
 */
public class KhuvucDAO extends HibernateDaoSupport {

    private Session session;

    /**
     *Rút trích danh sách tất cả khu vực
     *
     */
    public List dsKhuvucAll() {
        session = HibernateUtil.getSessionFactory().openSession();
        List list = null;
        try {
            org.hibernate.Transaction ts = session.beginTransaction();
            Criteria crit = session.createCriteria(Khuvuc.class);
            list = crit.list();
            ts.commit();
            session.flush();
        } catch (Exception ex) {
            System.err.println(ex.getMessage().toString());
        } finally {
            session.close();
        }
        return list;
    }
    public List dsKhuvucFi(int tinhTrang) {
        session = HibernateUtil.getSessionFactory().openSession();
        List list = null;
        try {
            org.hibernate.Transaction ts = session.beginTransaction();
            Criteria crit = session.createCriteria(Khuvuc.class).add(Restrictions.eq("tinhTrang", tinhTrang));
            list = crit.list();
            ts.commit();
            session.flush();
        } catch (Exception ex) {
            System.err.println(ex.getMessage().toString());
        } finally {
            session.close();
        }
        return list;
    }
    public Khuvuc getKhuVuc(int maKV) {

        Khuvuc kv = null;
        session = HibernateUtil.getSessionFactory().openSession();
        try {
            org.hibernate.Transaction ts = session.beginTransaction();
            Criteria crit = session.createCriteria(Khuvuc.class).add(Restrictions.idEq(maKV));
            List list = crit.list();
            kv = (Khuvuc) list.get(0);
            ts.commit();
            session.flush();
        } catch (Exception ex) {
            System.err.println(ex.getMessage().toString());
        } finally {
            session.close();
        }
        return kv;
    }
}
